home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1995 October / EnigmA AMIGA RUN 01 (1995)(G.R. Edizioni)(IT)[!][issue 1995-10][Aminet 7].iso / Aminet / dev / gui / textfield.lha / Textfield / MUITest / Main.c < prev    next >
C/C++ Source or Header  |  1995-06-23  |  3KB  |  127 lines

  1. /*
  2.  * MUI Test
  3.  *
  4.  * MUITest is a small example that shows how one would read
  5.  * the text from the Textfield gadget used in a MUI interface.
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. #include <exec/types.h>
  11. #include <libraries/mui.h>
  12. #include <intuition/classes.h>
  13. #include <gadgets/textfield.h>
  14.  
  15. #include <proto/muimaster.h>
  16. #include <proto/dos.h>
  17. #include <proto/exec.h>
  18. #include <proto/intuition.h>
  19.  
  20. #include <clib/alib_protos.h>
  21.  
  22. #include "muitest.h"
  23.  
  24. static BOOL init(void);
  25. static void clean(void);
  26.  
  27. struct Library *MUIMasterBase;
  28.  
  29. main()
  30. {
  31.     BOOL running = TRUE;
  32.     ULONG signal;
  33.     struct ObjApp *obj_app;
  34.  
  35.     if (init())
  36.     {
  37.         obj_app = CreateApp();
  38.         if (obj_app)
  39.         {
  40.             DoMethod(obj_app->window, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, obj_app->App, 2,
  41.                         MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  42.             DoMethod(obj_app->text, MUIM_Notify, TEXTFIELD_Lines, MUIV_EveryTime,
  43.                         obj_app->sbar, 3, MUIM_Set, MUIA_Prop_Entries, MUIV_TriggerValue);
  44.             DoMethod(obj_app->text, MUIM_Notify, TEXTFIELD_Visible, MUIV_EveryTime,
  45.                         obj_app->sbar, 3, MUIM_Set, MUIA_Prop_Visible, MUIV_TriggerValue);
  46.             DoMethod(obj_app->text, MUIM_Notify, TEXTFIELD_Top, MUIV_EveryTime,
  47.                         obj_app->sbar, 3, MUIM_NoNotifySet, MUIA_Prop_First, MUIV_TriggerValue);
  48.             DoMethod(obj_app->sbar, MUIM_Notify, MUIA_Prop_First, MUIV_EveryTime,
  49.                         obj_app->text, 3, MUIM_NoNotifySet, TEXTFIELD_Top, MUIV_TriggerValue);
  50.  
  51.             set(obj_app->window, MUIA_Window_Open, TRUE);
  52.  
  53.             while (running)
  54.             {
  55.                 switch (DoMethod(obj_app->App, MUIM_Application_Input, &signal))
  56.                 {
  57.                     case MUIV_Application_ReturnID_Quit:
  58.                         running = FALSE;
  59.                         break;
  60.                 }
  61.                 if (running && signal)
  62.                 {
  63.                     Wait(signal);
  64.                 }
  65.             }
  66.  
  67.             {
  68.                 struct Window *window;
  69.                 struct Gadget *gadget;
  70.                 char *text;
  71.                 ULONG size, i;
  72.  
  73.                 GetAttr(MUIA_Window_Window, obj_app->window, (ULONG *)&window);
  74.                 GetAttr(MUIA_Boopsi_Object, obj_app->text, (ULONG *)&gadget);
  75.                 if (window)
  76.                 {
  77.                     // Set to readonly mode so I can grab the text from the gadget
  78.                     SetGadgetAttrs(gadget, window, NULL, TEXTFIELD_ReadOnly, TRUE, TAG_DONE);
  79.                     GetAttr(TEXTFIELD_Size, gadget, &size);
  80.                     GetAttr(TEXTFIELD_Text, gadget, (ULONG *)&text);
  81.                     if (text && size)
  82.                     {
  83.                         for (i = 0; i < size; i++)
  84.                         {
  85.                             putchar(text[i]);
  86.                         }
  87.                     }
  88.                     SetGadgetAttrs(gadget, window, NULL, TEXTFIELD_ReadOnly, FALSE, TAG_DONE);
  89.                 }
  90.                 else
  91.                 {
  92.                     printf("No window\n");
  93.                 }
  94.  
  95.                 DisposeApp(obj_app);
  96.  
  97.                 // Version of MUI prior to 9 have a bug that
  98.                 // doesn't dispose of smart BOOPSI objects.
  99.                 if (MUIMasterBase->lib_Version < 9)
  100.                 {
  101.                     // Dispose of text gadget after disposing of
  102.                     // object that encapsulates the text gadget
  103.                     DisposeObject(gadget);
  104.                 }
  105.             }
  106.         }
  107.     }
  108. }
  109.  
  110. static BOOL init(void)
  111. {
  112.     MUIMasterBase = OpenLibrary(MUIMASTER_NAME,MUIMASTER_VMIN);
  113.     if (MUIMasterBase)
  114.     {
  115.         return TRUE;
  116.     }
  117.     else
  118.     {
  119.         return FALSE;
  120.     }
  121. }
  122.  
  123. static void clean(void)
  124. {
  125.     CloseLibrary(MUIMasterBase);
  126. }
  127.